package com.paschino.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.paschino.modal.User;

@Repository
public class UserDAOImpl extends AbstractDAO implements UserDAO {

	@SuppressWarnings("unchecked")
	@Override
	public User getUser(String username) {
		List<User> userList = new ArrayList<User>();
		Query query = getSession().createQuery(
				"from User u where u.username = :username").setParameter(
				"username", username);
		userList = query.list();
		if (userList.size() > 0)
			return userList.get(0);
		else
			return null;
	}

	@Override
	public void addUser(User user) {
		getSession().saveOrUpdate(user);
	}

	@Override
	public boolean updateUser(User user) {
		getSession().update(user);
		return true;
	}

}
